package com.vencent.quartz.java;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.SimpleScheduleBuilder.*;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

public class JobTest {
	public static void main(String[] args) {

		  SchedulerFactory schedFact = new StdSchedulerFactory();

		  try {
			Scheduler sched = schedFact.getScheduler();

			  sched.start();

			  // define the job and tie it to our HelloJob class
			  JobDetail job = newJob(HelloJob.class)
			      .withIdentity("myJob", "group1")
			      .build();

			  // Trigger the job to run now, and then every 40 seconds
			  Trigger trigger = newTrigger()
			      .withIdentity("myTrigger", "group1")
			      .startNow()
			      .withSchedule(simpleSchedule()
			          .withIntervalInSeconds(40)
			          .repeatForever())
			      .build();

			  // Tell quartz to schedule the job using our trigger
			  sched.scheduleJob(job, trigger);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
}
